﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using WF_DataAccess;
using ExtBusiness;
using WF_Business;

namespace ExtBusiness.Inspect
{
    /// <summary>
    /// 挂起信息操作
    /// </summary>
    public class SuspendInfo
    {
        /// <summary>
        /// 查询挂起日志
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="iid"></param>
        /// <returns></returns>
        public DataTable GetSuspendLog(string userid, string startDate, string endDate, string iid)
        {
            string strWhere = "";
            if (!string.IsNullOrEmpty(startDate))
            {
                strWhere += string.Format(" and start_date >=to_date('{0}','yyyy-MM-dd')", startDate);
            }
            if (!string.IsNullOrEmpty(endDate))
            {
                endDate = Convert.ToDateTime(endDate).AddDays(1).ToShortDateString();
                strWhere += string.Format(" and start_date < to_date('{0}','yyyy-MM-dd')", endDate);
            }
            if (!string.IsNullOrEmpty(iid))
            {
                strWhere += string.Format(" and iid='{0}'", iid);
            }

            bool IsSystemUser = Admin.SystemManager.IsSystemUser(userid);
            if (!IsSystemUser)
            {
                strWhere += string.Format(" and userid = '{0}'", userid);
            }
            string strSql = string.Format(@"select b.iid,
                   b.start_date,
                   b.end_date,
                   b.description,
                   (select user_name
                      from st_user t
                     where t.userid = b.userid
                       and rownum < 2) gqr,
                   (select user_name from st_user t where t.userid = b.end_userid and rownum < 2) jgr,
                   STPNAME
              from st_suspend b
             where 1=1 {0} 
             order by start_date desc", strWhere);
            DataTable dt = new DataTable();
            SysParams.OAConnection().RunSql(strSql, out dt);
            return dt;
        }

    }
}
